//
//  GTRefreshControl.swift
//  swiftWEIbo
//
//  Created by mac－gt on 15/11/30.
//  Copyright © 2015年 mac－gt. All rights reserved.
//

import UIKit

class GTRefreshControl: UIRefreshControl {

    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override init(){
        super.init()
  
        setUp()
        
    }
    private var isUp=false
    override var frame:CGRect{
        didSet{
    
            if frame.origin.y>0{
                return
            }
            if refreshing{
                self.refreshView.loadViewAnimation()
            }
            if frame.origin.y < -60 && !isUp{
                print("up")
                 isUp=true
                self.refreshView.srowViewAnimation(isUp)
               
            }else if frame.origin.y > -60 && isUp{
                print("down")
                isUp=false
                self.refreshView.srowViewAnimation(isUp)
            }
        
        }
    }
    func setUp(){
        self.addSubview(refreshView)
    refreshView.ff_AlignInner(type: ff_AlignType.CenterCenter, referView: self, size: refreshView.bounds.size)
        
    }
    override func endRefreshing() {
        super.endRefreshing()
        self.refreshView.stopLoad()
    }
    private lazy var refreshView: GTRefreshView=GTRefreshView.refreshView()
}
